
class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}




public class MiddleNode {
    public ListNode middleNode(ListNode head){
        //处理空链表清空
        if(head==null){
            return head;
        }
        //通过快慢指针的方法解决
        ListNode slow=head;
        ListNode fast=head;
        while(fast!=null&&fast.next!=null){
            slow=slow.next;
            fast=fast.next.next;
        }
        return slow;
    }
}